/****************************************************************************
**
** Copyright (C) 2018 Alexander Akulich <akulichalexander@gmail.com>
**
** Sailfish Silica UI is under copyright of Jolla Ltd.
**
** Based on Qt Material style
**
****************************************************************************/

#include <QtQuickControls2/private/qquickstyleplugin_p.h>

#include "qquicksilicastyle_p.h"
#include "qquicksilicatheme_p.h"

#include <QDebug>

QT_BEGIN_NAMESPACE

class QtQuickControls2SilicaStylePlugin : public QQuickStylePlugin
{
    Q_OBJECT
    Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid)

public:
    QtQuickControls2SilicaStylePlugin(QObject *parent = nullptr);

    void registerTypes(const char *uri) override;
    void initializeEngine(QQmlEngine *engine, const char *uri) override;

    QString name() const override;
    QQuickProxyTheme *createTheme() const override;
};

QtQuickControls2SilicaStylePlugin::QtQuickControls2SilicaStylePlugin(QObject *parent) : QQuickStylePlugin(parent)
{
    qWarning() << Q_FUNC_INFO;
}

void QtQuickControls2SilicaStylePlugin::registerTypes(const char *uri)
{
    qWarning() << Q_FUNC_INFO << uri;
    qmlRegisterModule(uri, 2, 0);
    qmlRegisterUncreatableType<QQuickSilicaStyle>(uri, 2, 0, "Silica", tr("Silica is an attached property"));
}

void QtQuickControls2SilicaStylePlugin::initializeEngine(QQmlEngine *engine, const char *uri)
{
    QQuickStylePlugin::initializeEngine(engine, uri);

//    engine->addImageProvider(name(), new QQuickColorImageProvider(QStringLiteral(":/qt-project.org/imports/QtQuick/Controls.2/Silica/images")));

    QByteArray import = QByteArray(uri) + ".impl";
    qmlRegisterModule(import, 2, 0);

    qmlRegisterType(typeUrl(QStringLiteral("SwitchIndicator.qml")), import, 2, 0, "SwitchIndicator");
}

QString QtQuickControls2SilicaStylePlugin::name() const
{
    return QStringLiteral("silica");
}

QQuickProxyTheme *QtQuickControls2SilicaStylePlugin::createTheme() const
{
    return new QQuickSilicaTheme;
}

QT_END_NAMESPACE

#include "qtquickcontrols2silicastyleplugin.moc"
